/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-06-22
 * Time: 21:55
 */
sealed class A permits B,C,D {//将密封类的继承权限开放给B,C,D
    //sealed修饰的类必须要有子类
    //且这些子类必须被final修饰或被sealed修饰或者被non-sealed修饰
}
non-sealed class B extends A {//子类可以被non-sealed修饰，表示 不限制

}
final class C extends A {//子类可以被final修饰

}
sealed class D extends A {//子类也可以被sealed修饰，这个子类也成为了密封类，这个子类也必须再有子类

}
non-sealed class E extends D {//继承被sealed修饰的D

}
public class Test {
    public static void main(String[] args) {
        var name = "dings";//Java会自动推导出name是String类型
        var age = 18;//Java会自动推导出age是int类型
        System.out.println(name+" "+age);
    }
    public static void main3(String[] args) {
        String flg = "three";
        int value = switch (flg) {//使用yield关键字来简化代码
            case "one" : yield 1;
            case "two" : yield 2;
            case "three" : yield 3;
            default : yield -1;
        };//注意这里要加;
        System.out.println(value);
    }
    public static void main2(String[] args) {
        String flg = "three";
        int value = switch (flg) {//使用 -> 来简化代码
            case "one" -> 1;
            case "two" -> 2;
            case "three" -> 3;
            default -> -1;
        };//注意这里要加;
        System.out.println(value);
    }
    public static void main1(String[] args) {
        int value = 0;
        String flg = "three";
        switch (flg) {
            case "one":
                value = 1;
                break;
            case "two":
                value = 2;
                break;
            case "three":
                value = 3;
                break;
            default:
                value = -1;
                break;
        }
        System.out.println(value);
    }
}
